package models;

import java.util.Collection;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import play.data.validation.Required;
import play.db.jpa.GenericModel;

@Entity
@Table(name = "role")
public class Role extends GenericModel {

    @Id
    @Column(name = "role_id")
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Long roleId;

    @Required
    @Column(name = "role_name")
    public String roleName;

    @ManyToMany(mappedBy = "roles")
    public Collection<User> users;

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = super.hashCode();
	result = prime * result + ((roleId == null) ? 0 : roleId.hashCode());
	result = prime * result
		+ ((roleName == null) ? 0 : roleName.hashCode());
	return result;
    }

    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (!super.equals(obj))
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	Role other = (Role) obj;
	if (roleId == null) {
	    if (other.roleId != null)
		return false;
	} else if (!roleId.equals(other.roleId))
	    return false;
	if (roleName == null) {
	    if (other.roleName != null)
		return false;
	} else if (!roleName.equals(other.roleName))
	    return false;
	return true;
    }

    @Override
    public String toString() {
	return "Role [roleId=" + roleId + ", roleName=" + roleName + "]";
    }

}
